---
layout: "default"
title: "_ArrayBufferType"
description: "Swift documentation for '_ArrayBufferType': The underlying buffer for an ArrayType conforms to."
keywords: "_ArrayBufferType,protocol,swift,documentation,_uninitializedCopy,generate,isMutableAndUniquelyReferenced,replace,requestNativeBuffer,requestUniqueMutableBackingBuffer,withUnsafeBufferPointer,withUnsafeMutableBufferPointer,baseAddress,capacity,count,identity,owner,endIndex,startIndex,Element,Generator,Index,_Element"
root: "/v1.2"
---

<div class="intro-declaration"><code class="language-swift">protocol _ArrayBufferType</code></div>

<div class="discussion comment">
    <p>The underlying buffer for an ArrayType conforms to
_ArrayBufferType.  This buffer does not provide value semantics.</p>
</div>

<table class="standard">
<tr>
<th id="inheritance">Inheritance</th>
<td>
<code class="inherits">CollectionType, MutableCollectionType, SequenceType, _CollectionType, _SequenceType, _Sequence_Type</code>
<span class="viz"><a href="hierarchy/">View Protocol Hierarchy &rarr;</a></span>
</td>
</tr>

<tr>
<th id="aliases">Associated Types</th>
<td>
<span id="aliasesmark"></span>
<div class="declaration">
<code class="language-swift">Element</code>
<div class="comment">
    <p>The type of elements stored in the buffer</p>
</div>
</div>
<div class="declaration inherited">
<code class="language-swift">Generator : GeneratorType</code>
<div class="comment">
    <p>A type that provides the <em>sequence</em>&#39;s iteration interface and
encapsulates its iteration state.</p>
</div>
</div>
<div class="declaration inherited">
<code class="language-swift">Index : ForwardIndexType</code>
<div class="comment">
    <p>A type that represents a valid position in the collection.</p>

<p>Valid indices consist of the position of every element and a
&quot;past the end&quot; position that&#39;s not valid for use as a subscript.</p>
</div>
</div>
<div class="declaration inherited">
<code class="language-swift">_Element</code>
<div class="comment">
    <p>A type that represents a valid position in the collection.</p>

<p>Valid indices consist of the position of every element and a
&quot;past the end&quot; position that&#39;s not valid for use as a subscript.</p>
</div>
</div>
</td>
</tr>


<tr>
<th>Import</th>
<td><code class="language-swift">import Swift</code></td>
</tr>

</table>


<h3>Initializers</h3>
<div class="declaration" id="init">
<a class="toggle-link" data-toggle="collapse" href="#comment-init">init()</a> <span class="required">Required</span><div class="comment collapse" id="comment-init"><div class="p">
    <p>create an empty buffer</p>

    <h4>Declaration</h4>    
    <code class="language-swift">init()</code>

    </div></div>
</div>
<div class="declaration" id="init_">
<a class="toggle-link" data-toggle="collapse" href="#comment-init_">init(<wbr>_:)</a> <span class="required">Required</span><div class="comment collapse" id="comment-init_"><div class="p">
    <p>Adopt the storage of x</p>

    <h4>Declaration</h4>    
    <code class="language-swift">init(_ buffer: _ContiguousArrayBuffer&lt;Element&gt;)</code>

    </div></div>
</div>


<h3>Instance Variables</h3>
<div class="declaration" id="var-baseaddress_-unsafemutablepointer-element">
<a class="toggle-link" data-toggle="collapse" href="#comment-var-baseaddress_-unsafemutablepointer-element">var baseAddress: UnsafeMutablePointer&lt;Element&gt;</a> <span class="required">Required</span><div class="comment collapse" id="comment-var-baseaddress_-unsafemutablepointer-element"><div class="p">
    <p>If the elements are stored contiguously, a pointer to the first
element. Otherwise, nil.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">var baseAddress: UnsafeMutablePointer&lt;Element&gt; { get }</code>

    </div></div>
</div>
<div class="declaration" id="var-capacity_-int">
<a class="toggle-link" data-toggle="collapse" href="#comment-var-capacity_-int">var capacity: Int</a> <span class="required">Required</span><div class="comment collapse" id="comment-var-capacity_-int"><div class="p">
    <p>How many elements the buffer can store without reallocation</p>

    <h4>Declaration</h4>    
    <code class="language-swift">var capacity: Int { get }</code>

    </div></div>
</div>
<div class="declaration" id="var-count_-int">
<a class="toggle-link" data-toggle="collapse" href="#comment-var-count_-int">var count: Int</a> <span class="required">Required</span><div class="comment collapse" id="comment-var-count_-int"><div class="p">
    <p>How many elements the buffer stores</p>

    <h4>Declaration</h4>    
    <code class="language-swift">var count: Int { get set }</code>

    </div></div>
</div>
<div class="declaration" id="var-identity_-unsafepointer-void">
<a class="toggle-link" data-toggle="collapse" href="#comment-var-identity_-unsafepointer-void">var identity: UnsafePointer&lt;Void&gt;</a> <span class="required">Required</span><div class="comment collapse" id="comment-var-identity_-unsafepointer-void"><div class="p">
    <p>A value that identifies the storage used by the buffer.  Two
buffers address the same elements when they have the same
identity and count.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">var identity: UnsafePointer&lt;Void&gt; { get }</code>

    </div></div>
</div>
<div class="declaration" id="var-owner_-anyobject">
<a class="toggle-link" data-toggle="collapse" href="#comment-var-owner_-anyobject">var owner: AnyObject</a> <span class="required">Required</span><div class="comment collapse" id="comment-var-owner_-anyobject"><div class="p">
    <p>An object that keeps the elements stored in this buffer alive</p>

    <h4>Declaration</h4>    
    <code class="language-swift">var owner: AnyObject { get }</code>

    </div></div>
</div>
<div class="declaration inherited" id="var-endindex_-index">
<a class="toggle-link" data-toggle="collapse" href="#comment-var-endindex_-index">var endIndex: Index</a> <span class="required">Required</span><div class="comment collapse" id="comment-var-endindex_-index"><div class="p">
    <p>The collection&#39;s &quot;past the end&quot; position.</p>

<p><code>endIndex</code> is not a valid argument to <code>subscript</code>, and is always
reachable from <code>startIndex</code> by zero or more applications of
<code>successor()</code>.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">var endIndex: Index { get }</code>

        <h4>Declared In</h4>
            <a href="../../protocol/_CollectionType/"><code>_CollectionType</code></a>
        </div></div>
</div>
<div class="declaration inherited" id="var-startindex_-index">
<a class="toggle-link" data-toggle="collapse" href="#comment-var-startindex_-index">var startIndex: Index</a> <span class="required">Required</span><div class="comment collapse" id="comment-var-startindex_-index"><div class="p">
    <p>The position of the first element in a non-empty collection.</p>

<p>Identical to <code>endIndex</code> in an empty collection.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">var startIndex: Index { get }</code>

        <h4>Declared In</h4>
            <a href="../../protocol/_CollectionType/"><code>_CollectionType</code></a>
        </div></div>
</div>

<h3>Subscripts</h3>
<div class="declaration" id="subscript-subscript_-int">
<a class="toggle-link" data-toggle="collapse" href="#comment-subscript-subscript_-int">subscript(_: Int)</a> <span class="required">Required</span>
<div class="comment collapse" id="comment-subscript-subscript_-int"><div class="p">
    

    <h4>Declaration</h4>    
    <code class="language-swift">subscript(index: Int) -&gt; Element { get nonmutating set }</code>
    
    
</div></div>
</div>
<div class="declaration" id="subscript-subscript_-range-int">
<a class="toggle-link" data-toggle="collapse" href="#comment-subscript-subscript_-range-int">subscript(_: Range&lt;Int&gt;)</a> <span class="required">Required</span>
<div class="comment collapse" id="comment-subscript-subscript_-range-int"><div class="p">
    

    <h4>Declaration</h4>    
    <code class="language-swift">subscript(subRange: Range&lt;Int&gt;) -&gt; _SliceBuffer&lt;Element&gt; { get }</code>
    
    
</div></div>
</div>
<div class="declaration inherited" id="subscript-subscript_-self-index">
<a class="toggle-link" data-toggle="collapse" href="#comment-subscript-subscript_-self-index">subscript(_: Self.Index)</a> <span class="required">Required</span>
<div class="comment collapse" id="comment-subscript-subscript_-self-index"><div class="p">
    

    <h4>Declaration</h4>    
    <code class="language-swift">subscript(position: Self.Index) -&gt; Self.Generator.Element { get }</code>
    
        <h4>Declared In</h4>
        <a href="../../protocol/CollectionType/"><code>CollectionType</code></a>,    <a href="../../protocol/MutableCollectionType/"><code>MutableCollectionType</code></a>    
</div></div>
</div>
<div class="declaration inherited" id="subscript-subscript_-index">
<a class="toggle-link" data-toggle="collapse" href="#comment-subscript-subscript_-index">subscript(_: Index)</a> <span class="required">Required</span>
<div class="comment collapse" id="comment-subscript-subscript_-index"><div class="p">
    

    <h4>Declaration</h4>    
    <code class="language-swift">subscript(_i: Index) -&gt; _Element { get }</code>
    
        <h4>Declared In</h4>
        <a href="../../protocol/_CollectionType/"><code>_CollectionType</code></a>    
</div></div>
</div>


<h3>Instance Methods</h3>
<div class="declaration" id="func--uninitializedcopy_target_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func--uninitializedcopy_target_">func _uninitializedCopy(<wbr>_:<wbr>target:)</a>
     <span class="required">Required</span>    
<div class="comment collapse" id="comment-func--uninitializedcopy_target_"><div class="p">
    <p>Copy the given subRange of this buffer into uninitialized memory
starting at target.  Return a pointer past-the-end of the
just-initialized memory.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func _uninitializedCopy(subRange: Range&lt;Int&gt;, target: UnsafeMutablePointer&lt;Element&gt;) -&gt; UnsafeMutablePointer&lt;Element&gt;</code>
    
    
</div></div>
</div>
<div class="declaration inherited" id="func-generate">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-generate">func generate()</a>
     <span class="required">Required</span>    
<div class="comment collapse" id="comment-func-generate"><div class="p">
    <p>Return a <em>generator</em> over the elements of this <em>sequence</em>.</p>

<p>Complexity: O(1)</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func generate() -&gt; Generator</code>
    
        <h4>Declared In</h4>
        <a href="../../protocol/SequenceType/"><code>SequenceType</code></a>,    <a href="../../protocol/_Sequence_Type/"><code>_Sequence_Type</code></a>    
</div></div>
</div>
<div class="declaration" id="func-ismutableanduniquelyreferenced">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-ismutableanduniquelyreferenced">mutating func isMutableAndUniquelyReferenced()</a>
     <span class="required">Required</span>    
<div class="comment collapse" id="comment-func-ismutableanduniquelyreferenced"><div class="p">
    <p>Returns true iff this buffer is backed by a uniquely-referenced mutable
_ContiguousArrayBuffer.</p>

<p>Note: this function must remain mutating; otherwise the buffer
may acquire spurious extra references, which will cause
unnecessary reallocation.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">mutating func isMutableAndUniquelyReferenced() -&gt; Bool</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-replace_with_elementsof_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-replace_with_elementsof_">mutating func replace(<wbr>_:<wbr>with:<wbr>elementsOf:)</a>
     <span class="required">Required</span>    
<div class="comment collapse" id="comment-func-replace_with_elementsof_"><div class="p">
    <p>Replace the given subRange with the first newCount elements of
the given collection.</p>

<p>Requires: this buffer is backed by a uniquely-referenced
_ContiguousArrayBuffer</p>

    <h4>Declaration</h4>    
    <code class="language-swift">mutating func replace&lt;C : CollectionType where Self.Element == Element&gt;(#subRange: Range&lt;Int&gt;, with newCount: Int, elementsOf newValues: C)</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-requestnativebuffer">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-requestnativebuffer">func requestNativeBuffer()</a>
     <span class="required">Required</span>    
<div class="comment collapse" id="comment-func-requestnativebuffer"><div class="p">
    <p>If this buffer is backed by a <code>_ContiguousArrayBuffer</code>
containing the same number of elements as <code>self</code>, return it.
Otherwise, return <code>nil</code>.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func requestNativeBuffer() -&gt; _ContiguousArrayBuffer&lt;Element&gt;?</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-requestuniquemutablebackingbuffer_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-requestuniquemutablebackingbuffer_">mutating func requestUniqueMutableBackingBuffer(<wbr>_:)</a>
     <span class="required">Required</span>    
<div class="comment collapse" id="comment-func-requestuniquemutablebackingbuffer_"><div class="p">
    <p>If this buffer is backed by a uniquely-referenced mutable
<em>ContiguousArrayBuffer that can be grown in-place to allow the self
buffer store minimumCapacity elements, returns that buffer.
Otherwise, returns nil.  Note: the result&#39;s baseAddress may
not match ours, if we are a </em>SliceBuffer.</p>

<p>Note: this function must remain mutating; otherwise the buffer
may acquire spurious extra references, which will cause
unnecessary reallocation.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">mutating func requestUniqueMutableBackingBuffer(minimumCapacity: Int) -&gt; _ContiguousArrayBuffer&lt;Element&gt;?</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-withunsafebufferpointer_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-withunsafebufferpointer_">func withUnsafeBufferPointer(<wbr>_:)</a>
     <span class="required">Required</span>    
<div class="comment collapse" id="comment-func-withunsafebufferpointer_"><div class="p">
    <p>Call <code>body(p)</code>, where <code>p</code> is an <code>UnsafeBufferPointer</code> over the
underlying contiguous storage.  If no such storage exists, it is
created on-demand.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func withUnsafeBufferPointer&lt;R&gt;(body: @noescape (UnsafeBufferPointer&lt;Element&gt;) -&gt; R) -&gt; R</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-withunsafemutablebufferpointer_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-withunsafemutablebufferpointer_">mutating func withUnsafeMutableBufferPointer(<wbr>_:)</a>
     <span class="required">Required</span>    
<div class="comment collapse" id="comment-func-withunsafemutablebufferpointer_"><div class="p">
    <p>Call <code>body(p)</code>, where <code>p</code> is an <code>UnsafeMutableBufferPointer</code>
over the underlying contiguous storage.  Requires: such
contiguous storage exists or the buffer is empty</p>

    <h4>Declaration</h4>    
    <code class="language-swift">mutating func withUnsafeMutableBufferPointer&lt;R&gt;(body: @noescape (UnsafeMutableBufferPointer&lt;Element&gt;) -&gt; R) -&gt; R</code>
    
    
</div></div>
</div>


